package com.levi.login.dao;

import com.levi.login.util.JdbcUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

    /**
     * @author 19838
     */
    public class UserDAO {

        /**
         * 判断用户名和密码对应的记录是否存在
         * @param username
         * @param password
         * @return
         */
        public boolean exist(String username, String password) {

            ResultSet resultSet =
                JdbcUtil.execute("SELECT COUNT(*) FROM user WHERE username = ? AND password = ? ", username, password);

            try {
                resultSet.next();
                int anInt = resultSet.getInt(1);
                if (anInt == 0) {
                    return false;
                } else {
                    return true;
                }
            } catch (SQLException throwable) {
                throwable.printStackTrace();
            }
            return false;
        }


    }


